package com.ruoyi.web.controller.subject;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.YcSubjectMainly;
import com.ruoyi.system.service.IYcSubjectMainlyService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 学科分类Controller
 * 
 * @author 杨琛
 * @date 2020-11-20
 */
@Controller
@RequestMapping("/system/mainly")
public class YcSubjectMainlyController extends BaseController
{
    private String prefix = "system/mainly";

    @Autowired
    private IYcSubjectMainlyService ycSubjectMainlyService;

    @RequiresPermissions("system:mainly:view")
    @GetMapping()
    public String mainly()
    {
        return prefix + "/mainly";
    }

    /**
     * 查询学科分类列表
     */
    @RequiresPermissions("system:mainly:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(YcSubjectMainly ycSubjectMainly)
    {
        startPage();
        List<YcSubjectMainly> list = ycSubjectMainlyService.selectYcSubjectMainlyList(ycSubjectMainly);
        return getDataTable(list);
    }

    /**
     * 导出学科分类列表
     */
    @RequiresPermissions("system:mainly:export")
    @Log(title = "学科分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(YcSubjectMainly ycSubjectMainly)
    {
        List<YcSubjectMainly> list = ycSubjectMainlyService.selectYcSubjectMainlyList(ycSubjectMainly);
        ExcelUtil<YcSubjectMainly> util = new ExcelUtil<YcSubjectMainly>(YcSubjectMainly.class);
        return util.exportExcel(list, "mainly");
    }

    /**
     * 新增学科分类
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存学科分类
     */
    @RequiresPermissions("system:mainly:add")
    @Log(title = "学科分类", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(YcSubjectMainly ycSubjectMainly)
    {
        return toAjax(ycSubjectMainlyService.insertYcSubjectMainly(ycSubjectMainly));
    }

    /**
     * 修改学科分类
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        YcSubjectMainly ycSubjectMainly = ycSubjectMainlyService.selectYcSubjectMainlyById(id);
        mmap.put("ycSubjectMainly", ycSubjectMainly);
        return prefix + "/edit";
    }

    /**
     * 修改保存学科分类
     */
    @RequiresPermissions("system:mainly:edit")
    @Log(title = "学科分类", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(YcSubjectMainly ycSubjectMainly)
    {
        return toAjax(ycSubjectMainlyService.updateYcSubjectMainly(ycSubjectMainly));
    }

    /**
     * 删除学科分类
     */
    @RequiresPermissions("system:mainly:remove")
    @Log(title = "学科分类", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ycSubjectMainlyService.deleteYcSubjectMainlyByIds(ids));
    }
}
